//
//  IndexListTableView.swift
//  downloadImage
//
//  Created by Galaxy on 2022/6/16.
//

import UIKit

class IndexListTableView: UITableView, UITableViewDelegate, UITableViewDataSource {
    
    var listArr:[[WebsiteModel]] = []
    var cellItemDidSelectedBlock:((_ indexPath:IndexPath)->())?

    override init(frame: CGRect, style: UITableView.Style) {
        super.init(frame: frame, style: style)
        delegate = self
        dataSource = self
        estimatedRowHeight = 0
        estimatedSectionFooterHeight = 0
        estimatedSectionHeaderHeight = 0
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        listArr.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        listArr[section].count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell.init(style: .default, reuseIdentifier: "cell")
        cell.textLabel?.text = listArr[indexPath.section][indexPath.row].name
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if self.cellItemDidSelectedBlock != nil {
            self.cellItemDidSelectedBlock!(indexPath)
        }
    }
    
    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        ["站点1","站点2","站点3","操作"][section]
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
